import { compileTemplate } from "./compile"

const DomNodePool = [];

export function createApp (options) {
  for (let option in options) {
    switch (option) {
      case "components":
        initComponent(options[option]);
        break;
        default:
          break;
    }
  }

  return {
    mount
  }
}
// 初始化事件
function initComponent (components) {
  for (let component of components) {
    let [templte, state] = component();
    const node = compileTemplate(templte,state);
    DomNodePool.push(node);
  }
}




function mount (el) {
  const app = document.querySelector(el);
  const oFlag = document.createDocumentFragment();
  DomNodePool.forEach(item => {
    oFlag.appendChild(item);
  })
  app.appendChild(oFlag);
}